package manage;

import login.ajiekou;
import login.vegetableList;

import java.time.LocalDate;
import java.util.*;

public class DishSys implements ajiekou<vegetableList> {
    static Map<String, vegetableList>dishmap=new HashMap<>();
    Set<String> keys=dishmap.keySet();




    //选择一个菜品，打算加入到订单里面
    public void selectByType(String typename)
    {
        int cnt=0;//菜品数目
        for(String key:keys)
        {
            if(Objects.equals(dishmap.get(key).getdType(),typename)){
                System.out.println(dishmap.get(key));
                cnt++;
            }
        }
        if(cnt==0){
            System.out.println("没有找到对应的商品");
        }
    }

    //添加一个菜品

    @Override
    public void insert(vegetableList v) {
        dishmap.put(v.getdID(),v);
    }

    //通过菜品类型查找
    public List<vegetableList> findByType(String type)
    {
        List<vegetableList>list=new ArrayList<>();
        for(String key:keys)
        {
            if(Objects.equals(type,dishmap.get(key).getdType())){
                list.add(dishmap.get(key));
            }
        }
        return list;
    }

    //根据商家id来找菜品
    public List<vegetableList> findBySlr(String uID)
    {
        List<vegetableList>list=new ArrayList<>();
        for(String key:keys)
        {
            if(Objects.equals(uID,dishmap.get(key).getCook().uID)){
                list.add(dishmap.get(key));
            }
        }
        if(list.size()>0){
            return list;
        }
        else{
            return null;
        }
    }
    //查找全部
    @Override
    public List<vegetableList> findall() {
        List<vegetableList>list = new ArrayList<>();


        for(String key:keys)
        {
            list.add(dishmap.get(key));
        }

        return list;
    }

    @Override
    public vegetableList findByID(String id) {
        if(dishmap.get(id)==null)
        {
            return null;
        }
        else {
            return dishmap.get(id);
        }
    }

    //删除指定id菜品
    @Override
    public void delete(String id) {
        if(dishmap.get(id)==null){
            System.out.println("该id下没有菜品");
        }
        else{
            dishmap.remove(id);
        }

    }
}
